package com.ydy.controller;

import java.util.List;

import javax.annotation.Resource;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.ydy.domain.Product;
import com.ydy.domain.Shop;
import com.ydy.service.ShopService;

/**
 * 
 * @ClassName: ShopController 
 * @Description: TODO
 * @author: 于鱼
 * @date: 2020年8月13日 上午8:38:46
 */
//一个新的注释
@Controller
public class ShopController {

	@Resource
	private ShopService shopService;
	
	/**
	 * 
	 * @Title: list 
	 * @Description: TODO
	 * @param model
	 * @param s
	 * @param pageNum
	 * @param pageSize
	 * @return
	 * @return: String
	 */
	@RequestMapping("/list")
	public String list(Model model,Shop s,@RequestParam(defaultValue = "1")Integer pageNum,@RequestParam(defaultValue = "3")Integer pageSize) {
		System.out.println(s);
		PageInfo<Shop> info = shopService.list(s,pageNum,pageSize);
		model.addAttribute("s", s);
		model.addAttribute("info", info);
		
		return "list";
	}
	
	@GetMapping("/add")
	public String add() {
		return "add";
	}
	@ResponseBody
	@PostMapping("/getProducts")
	public List<Product> getProducts(){
		List<Product> list = shopService.getProducts();
		
		return list;
	}
	@ResponseBody
	@PostMapping("/add")
	public boolean add(Shop s){
		//System.out.println(s);
		int i = shopService.add(s);
		
		return i>0;
	}
	@GetMapping("/show")
	public String show(String id,Model model) {
		Shop s = shopService.show(id);
		model.addAttribute("s", s);
		return "show";
	}
	@ResponseBody
	@PostMapping("/dels")
	public boolean dels(@RequestParam("ids[]")Integer[] ids) {
		
		int i = shopService.dels(ids);
		return i>0;
	}
	
	@GetMapping("/getOneForUpdate")
	public String getOneForUpdate(String id,Model model) {
		Shop s = shopService.getOneForUpdate(id);
		model.addAttribute("s", s);
		return "update";
	}
	
	@ResponseBody
	@PostMapping("/update")
	public boolean update(Shop s) {
		System.out.println("11111111111111111111");
		System.out.println(s);
		int i = shopService.update(s);
		
		return i>0;
	}
	
}
